package cn.terminus.web.customer.customdemand.controller;

import java.util.Date;

import cn.terminus.web.customer.customdemand.form.CustomDemandNewForm;
import cn.terminus.web.customer.customdemand.form.CustomDemandEditForm;
import cn.terminus.web.customer.customdemand.form.CustomDemandQueryForm;
import cn.terminus.web.customer.customdemand.form.CustomDemandDeleteForm;
import cn.terminus.web.customer.customdemand.form.CustomDemandGetsForm;
import cn.terminus.client.customer.customdemand.param.CustomDemandNewParam;
import cn.terminus.client.customer.customdemand.param.CustomDemandEditParam;
import cn.terminus.client.customer.customdemand.param.CustomDemandQueryParam;
import cn.terminus.client.customer.customdemand.param.CustomDemandDeleteParam;
import cn.terminus.client.customer.customdemand.param.CustomDemandGetsParam;
import cn.terminus.client.customer.customdemand.result.CustomDemandResult;
import cn.terminus.client.customer.customdemand.service.CustomDemandService;
import cn.terminus.result.common.result.TerminusResult;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.web.customer.common.AbstractTerminusController;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.exception.ServiceException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.terminus.result.common.util.BeanCopyUtils;
import cn.terminus.result.common.context.TerminusCallContext;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CustomDemand)控制层
 *
 * @author makejava
 * @version 1.0.0
 * @apiDefine CustomDemand $serviceComment
 * @since 2021-07-08 11:18:45
 */
@RestController
// todo 请修改path
@RequestMapping("/customDemand")
@Api(value = "(CustomDemand)控制层")
public class CustomDemandController extends AbstractTerminusController {
    /**
     * 服务对象
     */
    @Resource
    private CustomDemandService customDemandService;

    /**
     * @api {POST} /customDemand/add 新增
     * @apiVersion 1.0.0
     * @apiGroup CustomDemand
     * @apiName 新增
     * @apiDescription 新增
     * @apiParam (RequestBody) {Long} businessId  租户ID
     * @apiParam (RequestBody) {Long} cboCustomId  客户id
     * @apiParam (RequestBody) {String} cboDemandProvince  需求省市
     * @apiParam (RequestBody) {String} cboDemandCity  需求城市
     * @apiParam (RequestBody) {String} cboDemandCounty  需求区县
     * @apiParam (RequestBody) {String} cboDemandtPath  需求区域全路径
     * @apiParam (RequestBody) {Double} cboCustomMinHopeprice  期望价格最小
     * @apiParam (RequestBody) {Double} cboCustomMaxHopeprice  期望价格最大
     * @apiParam (RequestBody) {String} cboCustomHopepriceUnit  期望价格单位
     * @apiParam (RequestBody) {String} remark  备注
     * @apiParam (RequestBody) {Integer} status  状态
     * @apiParam (RequestBody) {String} createUser  create_user
     * @apiParam (RequestBody) {Date} createTime  create_time
     * @apiParam (RequestBody) {String} lastUpdateUser  last_update_user
     * @apiParam (RequestBody) {Date} lastUpdateTime  last_update_time
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {String} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":"[]"}
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}新增", httpMethod = "POST")
    public TerminusResult<String> add(@RequestBody CustomDemandNewForm form) {
        CustomDemandNewParam param = BeanCopyUtils.copyProperties(form, CustomDemandNewParam.class);
        try {
            return customDemandService.add(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("新增${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("新增${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }


    /**
     * @api {POST} /customDemand/edit 编辑
     * @apiVersion 1.0.0
     * @apiGroup CustomDemand
     * @apiName 编辑
     * @apiDescription 编辑
     * @apiParam (RequestBody) {Long} id  ID
     * @apiParam (RequestBody) {Long} businessId  租户ID
     * @apiParam (RequestBody) {Long} cboCustomId  客户id
     * @apiParam (RequestBody) {String} cboDemandProvince  需求省市
     * @apiParam (RequestBody) {String} cboDemandCity  需求城市
     * @apiParam (RequestBody) {String} cboDemandCounty  需求区县
     * @apiParam (RequestBody) {String} cboDemandtPath  需求区域全路径
     * @apiParam (RequestBody) {Double} cboCustomMinHopeprice  期望价格最小
     * @apiParam (RequestBody) {Double} cboCustomMaxHopeprice  期望价格最大
     * @apiParam (RequestBody) {String} cboCustomHopepriceUnit  期望价格单位
     * @apiParam (RequestBody) {String} remark  备注
     * @apiParam (RequestBody) {Integer} status  状态
     * @apiParam (RequestBody) {String} createUser  create_user
     * @apiParam (RequestBody) {Date} createTime  create_time
     * @apiParam (RequestBody) {String} lastUpdateUser  last_update_user
     * @apiParam (RequestBody) {Date} lastUpdateTime  last_update_time
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}编辑", httpMethod = "POST")
    public TerminusResult<Boolean> edit(@RequestBody CustomDemandEditForm form) {
        CustomDemandEditParam param = BeanCopyUtils.copyProperties(form, CustomDemandEditParam.class);
        try {
            return customDemandService.update(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("修改${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("修改${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /customDemand/delete 删除
     * @apiVersion 1.0.0
     * @apiGroup CustomDemand
     * @apiName 删除
     * @apiDescription 删除
     * @apiParam (RequestBody) {String[]} ids  ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}删除", httpMethod = "POST")
    public TerminusResult<Boolean> delete(@RequestBody CustomDemandDeleteForm form) {
        CustomDemandDeleteParam param = BeanCopyUtils.copyProperties(form, CustomDemandDeleteParam.class);
        try {
            return customDemandService.delete(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("删除${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("删除${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /customDemand/gets 详情
     * @apiVersion 1.0.0
     * @apiGroup CustomDemand
     * @apiName 详情
     * @apiDescription 详情
     * @apiParam (RequestBody) {String[]} ids  ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.businessId  租户ID
     * @apiSuccess (Success 200) {Long} data.datas.cboCustomId  客户id
     * @apiSuccess (Success 200) {String} data.datas.cboDemandProvince  需求省市
     * @apiSuccess (Success 200) {String} data.datas.cboDemandCity  需求城市
     * @apiSuccess (Success 200) {String} data.datas.cboDemandCounty  需求区县
     * @apiSuccess (Success 200) {String} data.datas.cboDemandtPath  需求区域全路径
     * @apiSuccess (Success 200) {Double} data.datas.cboCustomMinHopeprice  期望价格最小
     * @apiSuccess (Success 200) {Double} data.datas.cboCustomMaxHopeprice  期望价格最大
     * @apiSuccess (Success 200) {String} data.datas.cboCustomHopepriceUnit  期望价格单位
     * @apiSuccess (Success 200) {String} data.datas.remark  备注
     * @apiSuccess (Success 200) {Integer} data.datas.status  状态
     * @apiSuccess (Success 200) {String} data.datas.createUser  create_user
     * @apiSuccess (Success 200) {Date} data.datas.createTime  create_time
     * @apiSuccess (Success 200) {String} data.datas.lastUpdateUser  last_update_user
     * @apiSuccess (Success 200) {Date} data.datas.lastUpdateTime  last_update_time
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/gets", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}详情查询", httpMethod = "POST")
    public TerminusResult<List<CustomDemandResult>> gets(@RequestBody CustomDemandGetsForm form) {
        CustomDemandGetsParam param = BeanCopyUtils.copyProperties(form, CustomDemandGetsParam.class);
        try {
            return customDemandService.gets(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /customDemand/query 查询
     * @apiVersion 1.0.0
     * @apiGroup CustomDemand
     * @apiName 查询
     * @apiDescription 查询
     * @apiParam (RequestBody) {Long} businessId  租户ID
     * @apiParam (RequestBody) {Long} cboCustomId  客户id
     * @apiParam (RequestBody) {String} cboDemandProvince  需求省市
     * @apiParam (RequestBody) {String} cboDemandCity  需求城市
     * @apiParam (RequestBody) {String} cboDemandCounty  需求区县
     * @apiParam (RequestBody) {String} cboDemandtPath  需求区域全路径
     * @apiParam (RequestBody) {Double} cboCustomMinHopeprice  期望价格最小
     * @apiParam (RequestBody) {Double} cboCustomMaxHopeprice  期望价格最大
     * @apiParam (RequestBody) {String} cboCustomHopepriceUnit  期望价格单位
     * @apiParam (RequestBody) {String} remark  备注
     * @apiParam (RequestBody) {Integer} status  状态
     * @apiParam (RequestBody) {String} createUser  create_user
     * @apiParam (RequestBody) {Date} createTime  create_time
     * @apiParam (RequestBody) {String} lastUpdateUser  last_update_user
     * @apiParam (RequestBody) {Date} lastUpdateTime  last_update_time
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.businessId  租户ID
     * @apiSuccess (Success 200) {Long} data.datas.cboCustomId  客户id
     * @apiSuccess (Success 200) {String} data.datas.cboDemandProvince  需求省市
     * @apiSuccess (Success 200) {String} data.datas.cboDemandCity  需求城市
     * @apiSuccess (Success 200) {String} data.datas.cboDemandCounty  需求区县
     * @apiSuccess (Success 200) {String} data.datas.cboDemandtPath  需求区域全路径
     * @apiSuccess (Success 200) {Double} data.datas.cboCustomMinHopeprice  期望价格最小
     * @apiSuccess (Success 200) {Double} data.datas.cboCustomMaxHopeprice  期望价格最大
     * @apiSuccess (Success 200) {String} data.datas.cboCustomHopepriceUnit  期望价格单位
     * @apiSuccess (Success 200) {String} data.datas.remark  备注
     * @apiSuccess (Success 200) {Integer} data.datas.status  状态
     * @apiSuccess (Success 200) {String} data.datas.createUser  create_user
     * @apiSuccess (Success 200) {Date} data.datas.createTime  create_time
     * @apiSuccess (Success 200) {String} data.datas.lastUpdateUser  last_update_user
     * @apiSuccess (Success 200) {Date} data.datas.lastUpdateTime  last_update_time
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}查询", httpMethod = "POST")
    public TerminusResult<List<CustomDemandResult>> query(@RequestBody CustomDemandQueryForm form) {
        CustomDemandQueryParam param = BeanCopyUtils.copyProperties(form, CustomDemandQueryParam.class);
        try {
            return customDemandService.query(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /customDemand/page 分页查询
     * @apiVersion 1.0.0
     * @apiGroup CustomDemand
     * @apiName 分页查询
     * @apiDescription 分页查询
     * @apiParam (RequestBody) {Long} businessId  租户ID
     * @apiParam (RequestBody) {Long} cboCustomId  客户id
     * @apiParam (RequestBody) {String} cboDemandProvince  需求省市
     * @apiParam (RequestBody) {String} cboDemandCity  需求城市
     * @apiParam (RequestBody) {String} cboDemandCounty  需求区县
     * @apiParam (RequestBody) {String} cboDemandtPath  需求区域全路径
     * @apiParam (RequestBody) {Double} cboCustomMinHopeprice  期望价格最小
     * @apiParam (RequestBody) {Double} cboCustomMaxHopeprice  期望价格最大
     * @apiParam (RequestBody) {String} cboCustomHopepriceUnit  期望价格单位
     * @apiParam (RequestBody) {String} remark  备注
     * @apiParam (RequestBody) {Integer} status  状态
     * @apiParam (RequestBody) {String} createUser  create_user
     * @apiParam (RequestBody) {Date} createTime  create_time
     * @apiParam (RequestBody) {String} lastUpdateUser  last_update_user
     * @apiParam (RequestBody) {Date} lastUpdateTime  last_update_time
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {long} data.pageSize    分页大小
     * @apiSuccess (Success 200) {long} data.currentPage    当前页
     * @apiSuccess (Success 200) {long} data.totalPages    总页数
     * @apiSuccess (Success 200) {long} data.totalRows    总记录数
     * @apiSuccess (Success 200) {long} data.minRowNumber    当页起始行号
     * @apiSuccess (Success 200) {long} data.maxRowNumber    当页最大行号
     * @apiSuccess (Success 200) {Object[]} data.datas    列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.businessId  租户ID
     * @apiSuccess (Success 200) {Long} data.datas.cboCustomId  客户id
     * @apiSuccess (Success 200) {String} data.datas.cboDemandProvince  需求省市
     * @apiSuccess (Success 200) {String} data.datas.cboDemandCity  需求城市
     * @apiSuccess (Success 200) {String} data.datas.cboDemandCounty  需求区县
     * @apiSuccess (Success 200) {String} data.datas.cboDemandtPath  需求区域全路径
     * @apiSuccess (Success 200) {Double} data.datas.cboCustomMinHopeprice  期望价格最小
     * @apiSuccess (Success 200) {Double} data.datas.cboCustomMaxHopeprice  期望价格最大
     * @apiSuccess (Success 200) {String} data.datas.cboCustomHopepriceUnit  期望价格单位
     * @apiSuccess (Success 200) {String} data.datas.remark  备注
     * @apiSuccess (Success 200) {Integer} data.datas.status  状态
     * @apiSuccess (Success 200) {String} data.datas.createUser  create_user
     * @apiSuccess (Success 200) {Date} data.datas.createTime  create_time
     * @apiSuccess (Success 200) {String} data.datas.lastUpdateUser  last_update_user
     * @apiSuccess (Success 200) {Date} data.datas.lastUpdateTime  last_update_time
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}分页查询", httpMethod = "POST")
    public TerminusResult<TerminusPageAble<CustomDemandResult>> page(@RequestBody CustomDemandQueryForm form) {
        CustomDemandQueryParam param = BeanCopyUtils.copyProperties(form, CustomDemandQueryParam.class);
        try {
            TerminusPageInfo page = new TerminusPageInfo(form.getCurrentPage(), form.getRowsOfPage());
            return customDemandService.page(param, page, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("分页查询${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("分页查询${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

}
